@extends('pc_admin.app')

@section('content')
<link rel="stylesheet" href="{{asset('/addons/jquery-weui-build/css/weui.min.css')}}">
<link rel="stylesheet" href="{{asset('/addons/jquery-weui-build/css/jquery-weui.css')}}">
<link rel="stylesheet" href="/css/pc-system/attendance-left.css">
<link rel="stylesheet" href="/css/pc-system/new-colleague.css?v=2019013001">
<div class="mian-container">
    <div class="container-section new-colleague">
        @include(('pc_sysadmin.attendance_left'))
        <div class="right-section">
            <div class="colleague-header">
                <div class="colleague-top">
                    <img src="{{userlogo($user->id)}}">
                </div>
                <div style="text-align: center;">
                    <h3 class="change-h3">{{$user->qw_name}}</h3>
                    {{--@foreach($user->role as $ur)--}}
                        {{--<span class="circle-span span-reward">{{$rolearray[$ur]}}</span>--}}
                    {{--@endforeach--}}
                </div>
                <div class="colleague-list weui-cells">
                    <div class="weui-cell">
                        <i class="icon iconfont icon-xingbie"></i>
                        <p class="p-length">性别</p>
                        <div class="input-div">
                            <input class="weui-input sex" name="sex" readonly="readonly" type="text" value='{{$gender[$user->gender]}}'/>
                            <span class="weui-span"></span>
                        </div>
                    </div>
                    <div class="weui-cell">
                        <i class="icon iconfont icon-bumen1"></i>
                        <p class="p-length">部门</p>
                        <div class="input-div">
                            <input name="department" class="weui-input department" type="text" value='{{getGroupName($user->group_id)}}' data-values="{{$user->group_id}}"/>
                            <span class="weui-span"></span>
                        </div>
                    </div>
                    <div class="weui-cell">
                        <i class="icon iconfont icon-zhiwei"></i>
                        <p class="p-length">职位</p>
                        <div class="input-div">
                            <input class="weui-input position" name="position" type="text" @if($user->is_leader == 1) value='组长' @else value='组员' @endif  data-values="{{$user->is_leader}}"/>
                            <span class="weui-span"></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="a-link">
                <button class="weui-btn weui-btn_color save-info">保存</button>
                <a href="javascript:;" class="weui-btn weui-btn_warn delete-colleague">删除同事</a>
            </div>
            {!! csrf_field() !!}
            <input type="hidden" name="userid" value="{{$user->id}}">
        </div>
    </div>
</div>
<div class="list-shadow"></div>
<script src="{{asset('/addons/jquery-weui-build/js/jquery-weui.min.js')}}"></script>
<script>
  $(document).ready(function (){
      $(".sex").select({
          title: "选择性别",
          items: [{
              'title':'男',
              'value':'1',
          },{
              'title':'女',
              'value':'2',
          }],
          onOpen:function () {
              $('.list-shadow').css('display','block');
          },
          onClose:function () {
              $('.list-shadow').css('display','none');
          }
      });

      if($('.left-section').height()<$('.right-section').height()){
          $('.left-section').css('min-height',$('.right-section').height())
      }else{
          $('.right-section').css('min-height',$('.left-section').height());
      }
      var ddd = {!! $groups !!};
//      console.log(ddd)
      $(".department").select({
          title: "选择部门",
          items: ddd,
          onOpen:function () {
            $('.list-shadow').css('display','block');
          },
          onClose:function () {
              $('.list-shadow').css('display','none');
          }
      });

      $(".position").select({
          title: "选择职位",
          items: [{
              'title':'组长',
              'value':'1',
          },{
              'title':'组员',
              'value':'0',
          }],
          onOpen:function () {
              $('.list-shadow').css('display','block');
          },
          onClose:function () {
              $('.list-shadow').css('display','none');
          }
      });

    //删除同事
    $('.delete-colleague').click(function(){
        layer.confirm('确认将同事'+$('.change-h3').text()+'删除，并解除同事关系！', {
            btn : [ '确定', '取消' ]//按钮
        }, function(index) {
            //点击确认
            var userid = $('input[name=userid]').val();
            var token = $('input[name=_token]').val();
            $.ajax({
                'url': '/sysadmin/user/quit-company?_token='+token+'&userid='+userid,
                'type': 'POST',
                'data': '',
                error: function (request) {
                    layer.msg('网络错误', {icon: 2});
                },
                success: function (data) {
                    if (data.status == 'success') {
                        layer.msg("操作成功", {icon: 1});
                        setTimeout(function(){ window.location.href='/sysadmin/permission/index' }, 1000);
                    } else {
                        layer.msg(data.msg, {icon: 2});
                    }
                },
            });
            layer.close(index);
        });
    });

      $('.save-info').click(function(){
         var dep = $('input[name=department]').attr('data-values');
          var leader = $('input[name=position]').attr('data-values');
          var gender = $('input[name=sex]').attr('data-values');
          var userid = $('input[name=userid]').val();
          var token = $('input[name=_token]').val();
          $.ajax({
              'url': '/sysadmin/user/modify-user?_token='+token+'&userid='+userid,
              'type': 'POST',
              'data': '&is_leader='+leader+'&groupid='+dep+'&gender='+gender,
              error: function (request) {
                  console.log("error");
              },
              success: function (data) {
                  if (data.status == 'success') {
                      layer.msg("操作成功", {icon: 1});
                      setTimeout(function(){ window.location.href='/sysadmin/permission/index' }, 1000);
                  } else {
                      console.log("error");
                      layer.msg(data.msg, {icon: 2});
                  }
              },
          });
      });
  })
</script>
@endsection
